<layout name="page" />
<block name="content">
    <style>
        .tree_suggestion {
            overflow-x: hidden;
            overflow-y: scroll;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            height: 300px;
            width: 300px;
            background-color: #ffffff;
        }
    </style>
    {:widget('page_header/simple',array('name'=>'文电拟办'))}
    <form method='post' id="form_data" name="form_data" enctype="multipart/form-data"  >
        <input type="hidden" id="ajax" name="ajax" value="0">        
        
        
            <label class="input-label" for="name">
                标题：
            </label>
            <div class="col-sm-6">
                <input class="input" type="text" id="title" name="title" value="" check="required" info="请输入标题">
            </div>
        </div>
        
            <label class="input-label" for="name">
                类型：
            </label>
            <div class="col-sm-2">
                <select class="input" id="doc_type" name="doc_type">
                    <option value="0">一般文件</option>;<option value="1">红头文件</option>;
                </select>
            </div>
        </div>
        
            <label class="input-label" for="name">
                文档：
            </label>
            
                {:widget('file_upload/add')}
            </div>
        </div>
        
        <label class="input-label" for="name">
                拟办意见：
            </label>
            <div class="pull-left col-30">
                <div class="">
                    <h3><b>请</b></h3>
                </div>
                <div class="page_tree_menu">
                    <div id="personal" class="tree_suggestion">
                        <ul id="as" class="tree_menu">
                            <volist name="list" id="vo">
                                <li>
                                    <a>
                                        <label>
                                            &nbsp&nbsp<input id="ld_{$vo.id}" onclick="create_ld('{$vo.id}','{$vo.nickname}')" type="checkbox" name="ld_id[]" value="{$vo.id}"/><span>{$vo.nickname}</span>
                                        </label>
                                    </a>
                                </li>
                            </foreach>
                        </ul>
                    </div>
                    <h3><b>批示</b></h3>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="">
                    <h3><b>请</b></h3>
                </div>
                <div class="page_tree_menu">
                    <div id="personal2" class="tree_suggestion">
                        <ul class="tree_menu">
                            <volist name="list2" id="vo">
                                <li>
                                    <a>
                                        <label>
                                            &nbsp&nbsp<input  id="bm_{$vo.id}" onclick="create_bm('{$vo.id}','{$vo.dept_name}')" type="checkbox" name="bm_id[]" value="{$vo.dept_id}"/><span>{$vo.dept_name}</span>
                                        </label>
                                    </a>
                                </li>
                            </foreach>
                        </ul>
                    </div>
                    <h3><b>阅知</b></h3>
                </div>
            </div>
        </div>
      
      <label class="input-label" for="content"> 其他意见： </label>
			<div class="col-xs-6">
				<textarea id="yj" onkeyup="suggestion()" style="width:100%;height:100px;"></textarea>
			</div>
        </div>
        
            <label class="input-label" for="content">
                意见预览：
            </label>
            <div class="col-xs-6">
                <textarea id="content" name="content" readonly="readonly" style="width:100%;height:150px;"></textarea>
            </div>
        </div>
        
            
                <a class="btn btn-normal" onclick="save()">保存</a>
                <a class="btn btn-return" onclick="go_return_url()">取消 </a>
            </div>
        </div>
    </form>
</block>
<block name="js">
    <script type="text/javascript">
        function save(){
        	window.onbeforeunload = null;
        	 if ($("input:checked[name='ld_id[]']").length < 1) {
                ui_error("请指定领导批示！");
                return false;
            };
         if (check_form("form_data")) {
            var vars = $("#form_data").serialize();
            send_ajax("{:url('save_doc')}", vars, function(data){
                if (data.status) {
                    ui_alert(data.info, function(){
                       go_return_url();
                    });
                }
            });
           }
        }
        
  
        
        var obj = {};
        var all_ld_name = '';
        function create_ld(id, name){
            if ($("#ld_" + id).is(':checked')) {
                eval("obj.ld_" + id + "=" + "'" + name + "，'")
            }
            else {
                eval("delete obj.ld_" + id)
            }
            var ld_name = "请"
            for (var i in obj) {
                ld_name += eval("obj." + i);
            }
			ld_name += "签批，";
			if(!isNotNullObj(obj)){
				ld_name="" ;
			}
            
            all_ld_name = ld_name;
            var all_name=ld_name + all_bm_name;
            all_name=all_name.substring(0,all_name.length-1);
            all_name=all_name.replace(/，签批/, "签批")
            $("#content").val(all_name+"。");
            if($("#content").val()=='。'){
            	$("#content").val("");
            }
            
        }
        
        function isNotNullObj(obj){
            for (var i in obj) {
                if (obj.hasOwnProperty(i)) {
                    return true;
                }
            }
            return false;
        }
        
        var obj2 = {};
        var all_bm_name = "";
        function create_bm(id, name){
              if ($("#bm_" + id).is(':checked')) {
                eval("obj2.bm_" + id + "=" + "'" + name + "，'")
            }
            else {
                eval("delete obj2.bm_" + id)
            }

            var bm_name = "请"
            for (var i in obj2) {
                bm_name += eval("obj2." + i);
            }
			bm_name += "阅知,";
			if(!isNotNullObj(obj2)){
				bm_name="" ;
			}
            all_bm_name = bm_name;

            var all_name=all_ld_name + bm_name;
            all_name=all_name.substring(0,all_name.length-1);
            all_name=all_name.replace(/，阅知/, "阅知")
            all_name=all_name.replace(/，签批/, "签批")
            $("#content").val(all_name+"。");
            if($("#content").val()=='。'){
            	$("#content").val("");
            }
        }
        
        function suggestion(){
        	all_name=all_ld_name + all_bm_name + $("#yj").val();
        	all_name=all_name.replace(/，阅知/, "阅知");
            all_name=all_name.replace(/，签批/, "签批");
            $("#content").val(all_name);
        }
        
        $(document).ready(function(){
            $(document).on("click", ".inputbox .address_list a.del", function(){
                $(this).parent().parent().remove();
            });
        });
    </script>
</block>
